package com.tpsix.security.saas;

import lombok.experimental.UtilityClass;

/**
 * 多租户上下文
 */
@UtilityClass
public class TenantContextHolder {

    private final ThreadLocal<Long> TENANT_CONTEXT = ThreadLocal.withInitial(() -> 0L);

    public void setTenantId(Long tenantId) {
        TENANT_CONTEXT.set(tenantId);
    }

    public Long getTenantId() {
        return TENANT_CONTEXT.get();
    }

    public void clear() {
        TENANT_CONTEXT.remove();
    }

}
